
//
//  MyEvaViewC.m
//  WHSport
//
//  Created by ccjoy-jimneylee on 15/5/14.
//  Copyright (c) 2015年 jimneylee. All rights reserved.
//

#import "MyEvaViewC.h"
#import "UserModel.h"
#import "PlaceEntity.h"
#import <MBProgressHUD.h>

@interface MyEvaCell : UITableViewCell
@property(nonatomic, weak) IBOutlet UIImageView *starImg;
@property(nonatomic, weak) IBOutlet UILabel *nameLab;
@property(nonatomic, weak) IBOutlet UILabel *titleLab;
@property(nonatomic, weak) IBOutlet UILabel *dateLab;
@end
@implementation MyEvaCell
@end

@interface MyEvaViewC (){
    NSArray *dataArray;
}

@end

@implementation MyEvaViewC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title =@"我的评价";
    [self getData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)getData{
    NSString *idNum = [NSString stringWithFormat:@"%@",
                       [UserModel sharedInstance].currentUser.ID];
    NSString *ipage =@"1";
    [[UserModel sharedInstance]GetMyEvaWithAccountId:idNum page:ipage MyEva:^(id info) {
        NSArray *array = [info copy];
        dataArray = array;
        if (dataArray.count == 0) {
            MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
            HUD.labelText = @"没有数据";
            [HUD hide:YES afterDelay:1.5f];
        }
    }];
}

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete method implementation.
    // Return the number of rows in the section.
    return dataArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    MyEvaCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyEvaCellID" forIndexPath:indexPath];
    PlaceEntity *placeEty = dataArray[indexPath.row];
    cell.titleLab.text = placeEty.content;
    cell.nameLab.text = placeEty.loginName;
    cell.dateLab.text = placeEty.createtime;
    NSString *star = [NSString stringWithFormat:@"%@",placeEty.level];
    switch ([star intValue]) {
        case 0:
            cell.starImg.image = [UIImage imageNamed:@"nostar.png"];
            break;
        case 1:
            cell.starImg.image = [UIImage imageNamed:@"onestar.png"];
            break;
        case 2:
            cell.starImg.image = [UIImage imageNamed:@"twostar.png"];
            break;
        case 3:
            cell.starImg.image = [UIImage imageNamed:@"threestar.png"];
            break;
        case 4:
            cell.starImg.image = [UIImage imageNamed:@"fourstar.png"];
            break;
        case 5:
            cell.starImg.image = [UIImage imageNamed:@"allstar.png"];
            break;
        default:
            break;
    }
    
    return cell;
}


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
